﻿namespace WMS6.Web.Common
{
    using System;
    using System.Data;
    using System.Web.UI.HtmlControls;
    using WMS6.Web;
    using WMS6.Web.MessageServiceRef;

    public class GetMessageAjax : BasePage
    {
        protected HtmlForm form1;

        private void AjaxResponse(string strMessage)
        {
            base.Response.Clear();
            base.Response.StatusCode = 200;
            base.Response.StatusDescription = "OK";
            base.Response.ContentType = "text/html";
            base.Response.Write(strMessage);
            base.Response.Flush();
            base.Response.End();
        }

        private string GetMessageInfo()
        {
            UserMessageQueryEntity userMessageQuery = new UserMessageQueryEntity {
                ToUserID = "='" + base.UserInfo.UserID + "'",
                IsRead = "='N'",
                IsActive = "='N'"
            };
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            ds = MessageServiceClientProxy.GetInstance().GetInMessageInfoByQuery(userMessageQuery);
            string messageStr = "";
            if ((ds != null) && (ds.Tables.Count > 0))
            {
                dt = ds.Tables[0];
                if ((dt != null) && (dt.Rows.Count > 0))
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        string CS00002 = messageStr;
                        messageStr = CS00002 + dt.Rows[i]["MESSAGE_TITLE"].ToString() + "*" + dt.Rows[i]["MESSAGE_CONTENT"].ToString() + "|";
                    }
                }
            }
            return messageStr.TrimEnd(new char[] { '|' });
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.Page.Response.Buffer = false;
            this.Page.Response.Cache.SetNoStore();
            if (!string.IsNullOrEmpty(base.Request.QueryString["TYPE"]))
            {
                string strMessage = this.GetMessageInfo();
                this.AjaxResponse(strMessage);
            }
        }
    }
}

